package me.sealer.ssm.utils;

import me.sealer.ssm.constant.ErrorCodeConstant;
import org.springframework.web.servlet.support.RequestContext;

import javax.servlet.http.HttpServletRequest;

/**
 * 功能描述： $ MessageConvertorUtil
 *
 * @author sealer
 * @email 1178884049@qq.com
 * @date 2019年12月02日 16时13分36秒
 */
public class MessageConverterUtil {
    public static String getMessage(HttpServletRequest request, ErrorCodeConstant errorCodeConstant) {
        return getMessage(request, errorCodeConstant, null);
    }

    public static String getMessage(HttpServletRequest request, ErrorCodeConstant errorCodeConstant, Object[] args) {
        RequestContext requestContext = new RequestContext(request);
        String message = requestContext.getMessage(errorCodeConstant.getMessage(), args);
        return message;
    }

    public static String getMessage(HttpServletRequest request, String messageKey) {
        return getMessage(request, messageKey, null);
    }

    public static String getMessage(HttpServletRequest request, String messageKey, Object[] args) {
        RequestContext requestContext = new RequestContext(request);
        String message = requestContext.getMessage(messageKey, args);
        return message;
    }
}
